package com.zshan.clinic.web.controller.clinic;


import com.zshan.clinic.admin.entity.dto.ClinicInfoDTO;
import com.zshan.clinic.admin.entity.vo.ClinicInfoWebVo;
import com.zshan.clinic.admin.service.clinic.ClinicInfoService;
import com.zshan.clinic.common.enums.ReqSourceEnum;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.web.annotation.Permission;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import com.zshan.clinic.web.entity.request.AccountLoginRequest;
import com.zshan.clinic.web.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 诊所信息
 */
@RestController
@RequestMapping("/clinic/info")
public class ClinicInfoController extends AbstractController {


    @Autowired
    private ClinicInfoService clinicInfoService;

    @Autowired
    private LoginService loginService;

    /**
     * 叫号大屏：通过管理员账号获取诊所信息
     * @param
     * @return
     */
    @PostMapping("/getBoardClinicInfo")
    @Permission
    public RestResp<ClinicInfoWebVo> getBoardClinicInfo(@RequestBody @Valid AccountLoginRequest loginRequest){
        ClinicInfoWebVo clinicInfoWebVo = loginService.getBoardClinicInfo(loginRequest);
        return RestResp.SUCCESS(clinicInfoWebVo);
    }


    /**
     * 获取诊所信息
     * @param
     * @return
     */
    @GetMapping("/getClinicInfo")
    public RestResp<ClinicInfoWebVo> getClinicInfo(){
        UserInfo userInfo = getUserInfo();
        ClinicInfoWebVo clinicInfoWebVo = clinicInfoService.getClinicInfoForWeb(userInfo.getClinicId());
        return RestResp.SUCCESS(clinicInfoWebVo);
    }

    /**
     * 编辑诊所信息
     * @return
     */
    @PostMapping(value = "/update")
    public RestResp<Void> update(@RequestBody ClinicInfoDTO clinicInfoDTO) {
        UserInfo userInfo = getUserInfo();
        clinicInfoDTO.setUpdateUserId(userInfo.getEmpId());
        clinicInfoDTO.setUpdateBy(userInfo.getEmpName());
        clinicInfoDTO.setClinicId(userInfo.getClinicId());
        clinicInfoService.update(clinicInfoDTO, ReqSourceEnum.WEB.getValue());
        return RestResp.SUCCESS();
    }
}
